//
//  XYanalysis.m
//  英汉词典
//
//  Created by qianfeng on 15/8/11.
//  Copyright (c) 2015年 qianfeng. All rights reserved.
//

#import "XYanalysis.h"
#import "XYwords.h"

@interface XYanalysis(){
    NSMutableDictionary * _wordDict;
}

@end
@implementation XYanalysis
- (id) init{

    if (self = [super init]) {
        _wordDict = [[NSMutableDictionary alloc] init];
    }
    return self;
}

-(void)analysisWithPath:(NSString *)path{
   
    //把文件内容存到数据段中
   NSString * strFile = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
//解析
    //按照"#"分割，得到每个单词信息
    NSMutableArray * mfileArray = (NSMutableArray *)[strFile componentsSeparatedByString:@"#"];
      //删除空串
    for (NSString * tstr in mfileArray) {
//        NSLog(@"%@",tstr);
        
//        NSArray * array = [tstr componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\nTrans: "]];
//        NSLog(@"%@",array);
    
        NSArray *array1 = [tstr componentsSeparatedByString:@"\n"];
        NSLog(@"%@",array1);
        
        if (array1.count <= 2) {
            continue;
        }
        XYwords * model = [[XYwords alloc] initWithArray:array1];
        [_wordDict setObject:model forKey:model.English];
        NSLog(@"%@",model);
    }
}

- (void) findEnglishWithChinese:(NSString *)English{
    
    id word = [_wordDict objectForKey:English];
    
    if ([word isKindOfClass:[XYwords class]]) {
        NSLog(@"%@",word);
    }else{
        NSLog(@"该单词不存在");
    }
}

@end










